package com.hntest.controller;

import com.hntest.entity.Pager;
import com.hntest.entity.RealAuth;
import com.hntest.service.RealAuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/*
* 实名认证控制类
*
* */
@Controller("RealAuthController")
public class RealAuthController {
    @Autowired
    private RealAuthService realAuthService;
    public void setRealAuthService(RealAuthService realAuthService) {
        this.realAuthService = realAuthService;
    }
    @RequestMapping(value = "p2p/realauthselect",method = {RequestMethod.GET,RequestMethod.POST})
    public String select(Pager pager, RealAuth realAuth, ModelMap modelMap, HttpServletRequest request){
        String time1=request.getParameter("time1");
        String time2=request.getParameter("time2");
        List<RealAuth> list = realAuthService.getListByPage(pager,realAuth,time1,time2);
        modelMap.put("list",list);
        modelMap.put("pager",pager);
        modelMap.put("realAuth",realAuth);
        modelMap.put("time1",time1);
        modelMap.put("time2",time2);
        return "p2p/realauthselect";
    }

    @RequestMapping(value = "/realauthtoinsert")
    public String  toinsert(){
        return "realauthinsert";
    }

    @RequestMapping(value = "/realauthdoinsert")
    public  String doinsert(RealAuth realAuth){
        System.out.println(realAuth.getBorndate());
        int n = realAuthService.insert(realAuth);
        if(n>0){
            return "redirect:/realauth?op=auditYes";
        }else {
            return "redirect:/realauth?op=auditNo";
        }
    }

    @RequestMapping(value = "/realauthtoUpdate/{realauthid}")
    public String toUpdate(@PathVariable(value = "realauthid") int realauthid,ModelMap modelMap){
        RealAuth realAuth = realAuthService.getRealAuthById(realauthid);
        System.out.println("---------------->"+realauthid);
        modelMap.put("old",realAuth);
        return "realauthupdate";
    }

    @RequestMapping(value = "/realauthdoUpdate")
    public String doUpdate(RealAuth realAuth){
        realAuth.setAuditTime(new Date());
        int n = realAuthService.update(realAuth);
        if(n>0){
            return "redirect:/realauthselect?op=updateYes";
        }else {
            return "redirect:/realauthselect?op=updateNo";
        }
    }

}
